package com.example.demo.threadDemo.aCreateThread;

import java.util.concurrent.Callable;

/**
 * @Description MyThresd3
 * @Author songchuanlong
 * @Date 2025-04-14
 */

/**
 * 此类实现Callable接口
 */
public class MyThresd3 implements Callable<String> {
    /**
     * Computes a result, or throws an exception if unable to do so.
     *
     * @return computed result
     * @throws Exception if unable to compute a result
     */

    private int n;

    public MyThresd3(int n) {
        this.n = n;
    }

    //重写call方法
    @Override
    public String call() throws Exception {
        int sum=0;
        for (int i = 1; i <= n; i++) {
            sum+=i;
        }
        return "线程求出了1-"+n+"的和是："+sum;
    }
}
